<template>

	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-main" :isBack="true">
			<block slot="content">门店</block>
		</cu-custom>
		<view>
			<view class="fixed w-100" :style="{zIndex: 999}">
				<view :style="{height: StatusBar+'px'}" class="cu-bar bg-white search">
					<view class="search-form round">
						<text class="cuIcon-search"></text>
						<input type="text" v-model="searchObj.sname" placeholder="输入搜索的关键词" confirm-type="search"></input>
					</view>
					<view class="action">
						<button class="cu-btn bg-main  round" @tap="search">搜索</button>
					</view>
				</view>
				<view class="bg-white" :style="{height: StatusBar*0+'px'}">
					
				</view>
			</view>
			<view :style="{paddingTop: StatusBar*1+'px'}">
				<view class="margin-sm margin-bottom-xs shadow radius bg-white" v-for="(md,index) in stores" :key="index">
					<md-item :path="'/pages/cxy/md'" :md="md"></md-item>
				</view>
			</view>

			<!-- 显示更多按钮 -->
			<view class="padding" v-if="stores.length < pageInfo.total">
				<button @click="loadMore" class="cu-btn block bg-main lg">显示更多</button>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				CustomBar: this.CustomBar,
				StatusBar: this.StatusBar,
				searchObj: {
					sname: "",
				},
				pageInfo: {
					current: 1,
					size: 16,
					total: 0
				},
				stores: []

			};
		},
		
		computed: {
			currentPosition: function() {
				if (this.store.state.position) {
					return this.store.state.position;
				}
				return undefined;
			}
		},

		onLoad: function(option) {
			this.search();
		},
		onShareAppMessage: function(){
			return {
				title: this.store.state.title,
				path: '/pages/first?id='+this.store.state.client.clientid
			}
		},
		methods: {
			search: function() {
				this.stores = [];
				this.pageInfo.current = 1;
				this.loadStore();
			},
			loadMore: function() {
				this.pageInfo.current++;
				this.loadStore();
			},
			loadStore: function() {
				let param = {
					current: this.pageInfo.current,
					size: this.pageInfo.size,
					sname: this.searchObj.sname,
					flg: true
				};
				if (this.currentPosition) {
					param.jd = this.currentPosition.jd;
					param.wd = this.currentPosition.wd;
				}
				
				this.api("/md/page").send(param).then(data => {
					this.pageInfo.current = data.astores.current;
					this.pageInfo.total = data.astores.total;
					this.pageInfo.size = data.astores.size;
					for (let index in data.astores.records) {
						let record = data.astores.records[index];
						if (record.distance) {
							record.distance = this.util.formatDistance(record.distance);
						}
						this.stores.push(record);
					}
				});

			},


			// 卡片点击处理
			toStoreInfo: function(id) {
				uni.navigateTo({
					url: `/pages/md/mdxx?id=${id}` // 根据实际路由调整路径
				})
			}

		},


	}
</script>

<style>

</style>